//
//  UserCommentCell.m
//  HappyBaby
//
//  Created by 华哥 on 15/11/28.
//  Copyright © 2015年 华哥. All rights reserved.
//

#import "UserCommentCell.h"
#import "Define.h"
#import "UIImageView+WebCache.h"

@interface UserCommentCell ()

@end

@implementation UserCommentCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        self.userHeadImage = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 30, 30)];
        self.userHeadImage.layer.cornerRadius = 35 / 2;
        self.userHeadImage.layer.masksToBounds = YES;
        [self.contentView addSubview:_userHeadImage];
        
        self.username = [[UILabel alloc]initWithFrame:CGRectMake(60, 0, 200, 30)];
        [self.contentView addSubview:_username];
        
        self.commentLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.username.x, self.username.y + self.username.height + 20, kScreenWidth - self.username.x * 2, 300)];
        [self.contentView addSubview:_commentLabel];
    }
    return self;
}

- (void)setUserCommentModel:(UserCommentModel *)userCommentModel
{
    _userCommentModel = userCommentModel;
    self.username.text = userCommentModel.userInfoModel.username;
    
    CGSize commentSize = [self stringSizeWithFont:self.commentLabel.font string:userCommentModel.commentContent width:self.commentLabel.width];
    
    if (userCommentModel.userInfoModel.userHeadImage.length == 0)
    {
        [self.userHeadImage sd_setImageWithURL:[NSURL URLWithString:userCommentModel.userInfoModel.userHeadImage] placeholderImage:[UIImage imageNamed:@"iconfont-iconfontyonghutouxiang"]];
    }
    self.commentLabel.height = commentSize.height;
    self.commentLabel.text = userCommentModel.commentContent;
    UIView *bottomLine = [[UIView alloc]initWithFrame:CGRectMake(self.commentLabel.x, self.commentLabel.y + self.commentLabel.height + 5, self.commentLabel.width, 1)];
    bottomLine.layer.cornerRadius = 2;
    bottomLine.backgroundColor = [UIColor grayColor];
    [self addSubview:bottomLine];
}

- (CGSize)stringSizeWithFont:(UIFont *)font string:(NSString *)string width:(CGFloat)width
{
    CGRect rect = [string boundingRectWithSize:CGSizeMake(width, 10000) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:font} context:nil];
    return rect.size;
}























@end
